<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/6/27
 * Time: 3:48 PM
 */
namespace app\common\models;

class Permission extends BaseModel
{
    public $table = 'yq_permission';
    public $timestamps = true;
    protected $guarded = [''];
    const TYPE_USER = 1;
    const TYPE_ROLE = 2;

    public function roles()
    {
        return $this->belongsToMany(Role::class,'yq_permission_role','permission_id','role_id');
    }
    public static function deleteRolePermission($roleId)
    {
        return static::where('type', '=', static::TYPE_ROLE)->where('item_id', $roleId)->delete();
    }
    public static function deleteUserPermission($uid)
    {
        return static::where('type', '=', static::TYPE_USER)->where('item_id', $uid)->delete();
    }
}